package mm.chenchen.modules.mh.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import mm.chenchen.db.annotation.DataSource;
import mm.chenchen.modules.mh.entity.model.res.ChuTuLvModel;
import mm.chenchen.modules.mh.entity.model.res.ChuWoLvModel;
import org.springframework.stereotype.Service;
import mm.chenchen.utils.R;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import mm.chenchen.modules.mh.entity.MhIncome;
import mm.chenchen.modules.mh.dao.MhIncomeDao;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


@Service("mhIncomeService")
@DataSource("mh_game_local")
public class MhIncomeServiceImpl extends ServiceImpl<MhIncomeDao, MhIncome>  {

    public R saveInfo(MhIncome param){
        param.setCreateTime(new Date());
        return R.ok().setData(super.save(param));
    }

    public R<List<ChuWoLvModel>> getChuWoLv(){
        List<ChuWoLvModel> resList=new ArrayList<>();
        QueryWrapper<MhIncome> queryWrapper=new QueryWrapper<>();
        queryWrapper.lambda().eq(MhIncome::getType,"7");
        List<MhIncome> list=list(queryWrapper);
        Map<String,List<MhIncome>> map=list.stream().collect(Collectors.groupingBy(MhIncome::getRemak));

        map.forEach((key,e)->{
            ChuWoLvModel chuWoLvModel =new ChuWoLvModel();
            chuWoLvModel.setName(key);
            e.forEach(tmp->{
                chuWoLvModel.add(tmp.getFrequency().intValue(),tmp.getThingCount().intValue());
            });
            switch (key){
                case "垂耳兔":
                    chuWoLvModel.setDescription("50分窝,550积分饲料,第15天卖,10天繁殖期");
                    chuWoLvModel.setRiJiFen(44.67d);
                    chuWoLvModel.setMinChuWoLv(10d);
                    break;
                case "树袋熊":

                case "老虎":
                    chuWoLvModel.setDescription("50分窝,150积分饲料,第10天卖,7天繁殖期");
                    chuWoLvModel.setRiJiFen(44.8d);
                    chuWoLvModel.setMinChuWoLv(14.29d);
                    break;
                case "孔雀":
                    chuWoLvModel.setMinChuWoLv(33.34d);
                    chuWoLvModel.setDescription("50分窝,白嫖典范,第10天卖,3天繁殖期");
                    chuWoLvModel.setRiJiFen(27.4d);
                    break;
            }
            resList.add(chuWoLvModel);
        });
        return R.ok().setData(resList);
    }

    public R getChuTuLv(){
        List<ChuTuLvModel> resList=new ArrayList<>();

        QueryWrapper<MhIncome> queryWrapper=new QueryWrapper<>();
        queryWrapper.lambda().eq(MhIncome::getType,"2");
        List<MhIncome> list=list(queryWrapper);
        Map<String,List<MhIncome>> map=list.stream().collect(Collectors.groupingBy(MhIncome::getRemak));
        Long xx=0l;
        map.forEach((key,e)->{
            ChuTuLvModel chuTuLvModel =new ChuTuLvModel();

            List<ChuTuLvModel> ch=new ArrayList<>();
            chuTuLvModel.setRoleName(key);
            e.forEach(tmp->{
                ChuTuLvModel chTmp =new ChuTuLvModel();
                chTmp.setRoleName(key);
                chTmp.setRoleLevel(tmp.getRoleLevel());
                chTmp.add(tmp.getFrequency().intValue(),tmp.getThingCount().intValue(),tmp.getTimes());
                ch.add(chTmp);

                chuTuLvModel.setRoleLevel(tmp.getRoleLevel());
                chuTuLvModel.add(tmp.getFrequency().intValue(),tmp.getThingCount().intValue(),tmp.getTimes());
            });
            chuTuLvModel.setChildren(ch);
            resList.add(chuTuLvModel);
        });
        return R.ok().setData(resList);
    }

}